unit UModule_Absensi;

interface

uses
  Dialogs,
  Controls,
  SysUtils,
  Classes,
  InvokeRegistry,
  Rio,
  SOAPHTTPClient,
  ActnList;

type
  TModule_Absensi = class(TDataModule)
    ActionList1: TActionList;
    HTTPRIO1: THTTPRIO;
    PFile_Simpan: TAction;
    PFile_Refresh: TAction;
    PFile_Edit: TAction;
    PFile_Hapus: TAction;
    PMenu_Data: TAction;
    procedure HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream);
    procedure PFile_SimpanExecute(Sender: TObject);
    procedure PFile_RefreshExecute(Sender: TObject);
    procedure PFile_EditExecute(Sender: TObject);
    procedure PFile_HapusExecute(Sender: TObject);
    procedure PMenu_DataExecute(Sender: TObject);
    procedure DataModuleCreate(Sender: TObject);
  private
    FAbsensiStatus_Simpan: string;
    FAbsensiStatus_ID:     word;
    procedure Assign_LoginInfo;
  public
    procedure Assign_Action;
  end;

var
  Module_Absensi: TModule_Absensi;

implementation

uses
  UMainApplication,
  UUser,
  soap_sis_absensi;
{$R *.dfm}

procedure TModule_Absensi.Assign_Action;
begin
try
  with Form_Main do
    begin
    TMB0105010601020101.Action := PFile_Simpan;
    TMB0105010601020102.Action := PFile_Edit;
    TMB0105010601020103.Action := PFile_Hapus;
    TMB0105010601020104.Action := PFile_Refresh;
    with CB010501 do
      begin
      with Categories[5] do
        begin
        Items[2].Action := PMenu_Data;
        end;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.Assign_LoginInfo;
begin
try
  with Form_Main do
    begin
    GServer_Host     := IN010301.Text;
    GServer_Database := IN010302.Text;
    GServer_UserName := IN010303.Text;
    GServer_Password := IN010304.Text;
    GUserName        := LE01010101.Text;
    GUserPassword    := LE01010102.Text;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.DataModuleCreate(Sender: TObject);
begin
try
  FAbsensiStatus_Simpan := 'NEW';
  FAbsensiStatus_ID     := 0;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream);
var
  LocalStrings: TStringList;
begin
try
  LocalStrings          := TStringList.Create;
  SOAPResponse.Position := 0;
  LocalStrings.LoadFromStream(SOAPResponse);
  // ShowMessage(LocalStrings.Text);
  FreeAndNil(LocalStrings);
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.PFile_EditExecute(Sender: TObject);
begin
try
  with Form_Main, Grid01050106010201 do
    begin
    FAbsensiStatus_Simpan := 'EDIT';
    FAbsensiStatus_ID     := Cell[1, SelectedRow].AsInteger;
    IN01050106010201.Text := Cell[2, SelectedRow].AsString;
    IN01050106010202.Text := Cell[3, SelectedRow].AsString;
    IN01050106010203.Text := Cell[4, SelectedRow].AsString;
    with IN01050106010201 do
      begin
      Show;
      SetFocus;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.PFile_HapusExecute(Sender: TObject);
var
  InfoServer: TInfoServer;
begin
try
  case MessageDlg('Apakah anda yakin akan menghapus data absensi ini?', mtConfirmation, [mbYes, mbCancel], 0) of
    mrYes:
      begin
      Assign_LoginInfo;
      InfoServer                 := TInfoServer.Create;
      InfoServer.Server_Host     := GServer_Host;
      InfoServer.Server_Database := GServer_Database;
      InfoServer.Server_Username := GServer_UserName;
      InfoServer.Server_Password := GServer_Password;
      with Form_Main, HTTPRIO1 as SERVICE_ABSENSIPortType do
        begin
        ABSENSI_HAPUS(InfoServer, Grid01050106010201.Cell[1, Grid01050106010201.SelectedRow].AsInteger);
        with Grid01050106010201 do
          begin
          BeginUpdate;
          DeleteRow(SelectedRow);
          EndUpdate;
          end;
        end;
      end;
    mrCancel:
      begin
      // Ignore this process
      end;
  end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.PFile_RefreshExecute(Sender: TObject);
var
  InfoServer:              TInfoServer;
  InfoDaftarAbsensiStatus: TInfoDaftarAbsensiStatus;
  LocalIndex:              word;
  LocalCount:              word;
begin
try
  InfoServer := TInfoServer.Create;
  Assign_LoginInfo;
  with Form_Main, HTTPRIO1 as SERVICE_ABSENSIPortType do
    begin
    InfoServer.Server_Host     := GServer_Host;
    InfoServer.Server_Database := GServer_Database;
    InfoServer.Server_Username := GServer_UserName;
    InfoServer.Server_Password := GServer_Password;
    InfoDaftarAbsensiStatus    := ABSENSI_DATA_SEMUA(InfoServer, 'ASC');
    LocalCount                 := high(InfoDaftarAbsensiStatus);
    if LocalCount > 0 then
      begin
      with Grid01050106010201 do
        begin
        BeginUpdate;
        ClearRows;
        AddRow(LocalCount + 1);
        for LocalIndex := 0 to LocalCount do
          begin
          Grid01050106010201.Cell[1, LocalIndex].AsInteger := InfoDaftarAbsensiStatus[LocalIndex].ID;
          Grid01050106010201.Cell[2, LocalIndex].AsString  := InfoDaftarAbsensiStatus[LocalIndex].ABSENSI_KODE;
          Grid01050106010201.Cell[3, LocalIndex].AsString  := InfoDaftarAbsensiStatus[LocalIndex].ABSENSI_NAMA;
          Grid01050106010201.Cell[4, LocalIndex].AsString  := InfoDaftarAbsensiStatus[LocalIndex].ABSENSI_KETERANGAN;
          end;
        EndUpdate;
        end;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.PFile_SimpanExecute(Sender: TObject);
var
  InfoServer:  TInfoServer;
  InfoAbsensi: TInfoAbsensiStatus;
begin
try
  Assign_LoginInfo;
  InfoServer                 := TInfoServer.Create;
  InfoAbsensi                := TInfoAbsensiStatus.Create;
  InfoServer.Server_Host     := GServer_Host;
  InfoServer.Server_Database := GServer_Database;
  InfoServer.Server_Username := GServer_UserName;
  InfoServer.Server_Password := GServer_Password;
  with Form_Main, HTTPRIO1 as SERVICE_ABSENSIPortType do
    begin
    InfoAbsensi.ID                 := FAbsensiStatus_ID;
    InfoAbsensi.ABSENSI_KODE       := IN01050106010201.Text;
    InfoAbsensi.ABSENSI_NAMA       := IN01050106010202.Text;
    InfoAbsensi.ABSENSI_KETERANGAN := IN01050106010203.Text;
    ABSENSI_SIMPAN(InfoServer, InfoAbsensi, FAbsensiStatus_Simpan);
    with Grid01050106010201 do
      begin
      Show;
      PFile_Refresh.Execute;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Absensi.PMenu_DataExecute(Sender: TObject);
begin
try
  with Form_Main, TAB010501060102 do
    begin
    Show;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

end.
